@@ -15,7 +15,7 @@ module SortableTable |
||
| 15 | 15 |
end |
| 16 | 16 |
|
| 17 | 17 |
def set_table_sort(sort_options) |
| 18 |
- valid_sorts = sort_options[:sorts] || raise("You must specify :sorts as an array of valid sort attributes.")
|
|
| 18 |
+ valid_sorts = sort_options[:sorts] or raise ArgumentError.new("You must specify :sorts as an array of valid sort attributes.")
|
|
| 19 | 19 |
default = sort_options[:default] || { valid_sorts.first.to_sym => :desc }
|
| 20 | 20 |
|
| 21 | 21 |
if params[:sort].present? |
@@ -37,7 +37,15 @@ module SortableTable |
||
| 37 | 37 |
end |
| 38 | 38 |
|
| 39 | 39 |
module SortableTableHelper |
| 40 |
- def sortable_column(attribute, name = attribute.humanize, default_direction = 'desc') |
|
| 40 |
+ # :call-seq: |
|
| 41 |
+ # sortable_column(attribute, default_direction = 'desc', name: attribute.humanize) |
|
| 42 |
+ def sortable_column(attribute, default_direction = nil, options = nil) |
|
| 43 |
+ if options.nil? && (options = Hash.try_convert(default_direction)) |
|
| 44 |
+ default_direction = nil |
|
| 45 |
+ end |
|
| 46 |
+ default_direction ||= 'desc' |
|
| 47 |
+ options ||= {}
|
|
| 48 |
+ name = options[:name] || attribute.humanize |
|
| 41 | 49 |
selected = @table_sort_info[:attribute].to_s == attribute |
| 42 | 50 |
if selected |
| 43 | 51 |
direction = @table_sort_info[:direction] |
@@ -50,4 +58,4 @@ module SortableTable |
||
| 50 | 58 |
link_to(name, url_for(sort: "#{attribute}.#{new_direction}"), class: classes)
|
| 51 | 59 |
end |
| 52 | 60 |
end |
| 53 |
-end |
|
| 61 |
+end |
@@ -1,11 +1,11 @@ |
||
| 1 | 1 |
<div class='table-responsive'> |
| 2 | 2 |
<table class='table table-striped'> |
| 3 | 3 |
<tr> |
| 4 |
- <th><%= sortable_column 'name', 'Name', 'asc' %></th> |
|
| 4 |
+ <th><%= sortable_column 'name', 'asc' %></th> |
|
| 5 | 5 |
<th>Schedule</th> |
| 6 |
- <th><%= sortable_column 'last_check_at', 'Last Check' %></th> |
|
| 7 |
- <th><%= sortable_column 'last_event_at', 'Last Event Out' %></th> |
|
| 8 |
- <th><%= sortable_column 'last_receive_at', 'Last Event In' %></th> |
|
| 6 |
+ <th><%= sortable_column 'last_check_at', name: 'Last Check' %></th> |
|
| 7 |
+ <th><%= sortable_column 'last_event_at', name: 'Last Event Out' %></th> |
|
| 8 |
+ <th><%= sortable_column 'last_receive_at', name: 'Last Event In' %></th> |
|
| 9 | 9 |
<th>Events Created</th> |
| 10 | 10 |
<th>Working?</th> |
| 11 | 11 |
<th></th> |
@@ -12,7 +12,7 @@ |
||
| 12 | 12 |
|
| 13 | 13 |
<table class='table table-striped'> |
| 14 | 14 |
<tr> |
| 15 |
- <th><%= sortable_column 'name', 'Name', 'asc' %></th> |
|
| 15 |
+ <th><%= sortable_column 'name', 'asc' %></th> |
|
| 16 | 16 |
<th>Agents</th> |
| 17 | 17 |
<th><%= sortable_column 'public' %></th> |
| 18 | 18 |
<th></th> |
@@ -25,9 +25,9 @@ |
||
| 25 | 25 |
<div class='table-responsive'> |
| 26 | 26 |
<table class='table table-striped events'> |
| 27 | 27 |
<tr> |
| 28 |
- <th><%= sortable_column 'provider', 'Provider', 'asc' %></th> |
|
| 29 |
- <th><%= sortable_column 'name', 'Name', 'asc' %></th> |
|
| 30 |
- <th><%= sortable_column 'global', 'Global?' %></th> |
|
| 28 |
+ <th><%= sortable_column 'provider', 'asc' %></th> |
|
| 29 |
+ <th><%= sortable_column 'name', 'asc' %></th> |
|
| 30 |
+ <th><%= sortable_column 'global', name: 'Global?' %></th> |
|
| 31 | 31 |
<th></th> |
| 32 | 32 |
</tr> |
| 33 | 33 |
|
@@ -14,8 +14,8 @@ |
||
| 14 | 14 |
|
| 15 | 15 |
<table class='table table-striped'> |
| 16 | 16 |
<tr> |
| 17 |
- <th><%= sortable_column 'credential_name', 'Name', 'asc' %></th> |
|
| 18 |
- <th><%= sortable_column 'credential_value', 'Value', 'asc' %></th> |
|
| 17 |
+ <th><%= sortable_column 'credential_name', 'asc', name: 'Name' %></th> |
|
| 18 |
+ <th><%= sortable_column 'credential_value', 'asc', name: 'Value' %></th> |
|
| 19 | 19 |
</tr> |
| 20 | 20 |
|
| 21 | 21 |
<% @user_credentials.each do |user_credential| %> |